package com.taxicall.client;

import java.util.List;

import com.taxicall.entities.NetworkMessage;
import com.taxicall.entities.Taxi;
import com.taxicall.entities.TaxiLocation;

import android.os.Bundle;
import android.os.Handler;
import android.os.Parcelable;
import android.os.ResultReceiver;

public class MyResultReceiver extends ResultReceiver {
	
	public static final int TAXI_RESULTS = 1;
	public static final int TAXI_LOCATIONS_RESULTS = 2;
	public static final int RIDE_REPLY = 3;
	public static final int TIMEOUT_REACHED = 4;

	public MyResultReceiver(Handler handler) {
		super(handler);
	}

	protected void onReceiveResult(int resultCode, Bundle results) {
		if(resultCode == TAXI_LOCATIONS_RESULTS) {
			NetworkMessage msg = (NetworkMessage) results.getSerializable("receivedMsg");
			ClientIntro.getTaxiLocations((List<TaxiLocation>) msg.getDataObject());
		}
		else if(resultCode == TAXI_RESULTS) {
			NetworkMessage msg = (NetworkMessage) results.getSerializable("receivedMsg");
			DestinationSelection.getTaxis((List<Taxi>) msg.getDataObject());
		}
		else if(resultCode == RIDE_REPLY) {
			NetworkMessage msg = (NetworkMessage) results.getSerializable("receivedMsg");
			DestinationSelection.getAnswer((String) msg.getDataObject());
		}
		else if(resultCode == TIMEOUT_REACHED) {
			DestinationSelection.receivedTimeout();
		}
	}
}
